// ObserverMineGrid.cpp

#include "ObserverMineGrid.h"
#include <iostream>

/**
 * Constructor.
 */
ObserverMineGrid::ObserverMineGrid()
: grid( new MineGrid() )
{
	grid->resize( Size( 10, 10 ) );
}

/**
* Constructor. Resizes the grid to the given size.
*
* @param size the new size.
*/
ObserverMineGrid::ObserverMineGrid( const Size& size )
: grid( new MineGrid() )
{
	grid->resize( size );
}

/**
 * Destructor.
 */
ObserverMineGrid::~ObserverMineGrid()
{
	delete grid;
}

/**
* Resets the grid.
*/
void ObserverMineGrid::reset()
{
	grid->reset();
	notifyAll();
}

/**
 * Returns the size of the grid.
 *
 * @return Size the size of the grid.
 */
Size ObserverMineGrid::getGridSize() const
{
	return grid->getSize();
}

/**
* Returns the elapsed time.
*
* @return int the currently elapsed time.
*/
int ObserverMineGrid::getElapsedTime() const
{
	return 1;
}

/**
* Checks if the player is done with the game
*
* @return bool if the grid is finished.
*/
bool ObserverMineGrid::isDone() const
{
	return grid->isDone();
}

/**
* Checks if the mine has been swept.
*
* @return bool if the mine has been swept.
*/
bool ObserverMineGrid::isSwept( const Point& p ) const
{
	return grid->isSwept( p );
}

/**
 * Sweeps the mine.
 */
void ObserverMineGrid::sweepMine( const Point& p )
{
	grid->sweepMine( p );
	notifyAll();
}

/**
* Checks if the mine has been flagged.
*
* @return bool if the mine has been flagged.
*/
bool ObserverMineGrid::isFlagged( const Point& p ) const
{
	return grid->isFlagged( p );
}

/**
* Flags the mine.
*/
void ObserverMineGrid::flagMine( const Point& p )
{
	grid->flagMine( p );
	notifyAll();
}

/**
* Checks wether or not the square is a mine or not.
*
* @return bool if the square is a mine or not.
*/
bool ObserverMineGrid::isMine( const Point& p ) const
{
	return grid->isMine( p );
}

/**
 * Returns the status of the mine at the given point
 * in the grid.
 *
 * @return int the state of the mine.
 */
int ObserverMineGrid::getMineState( const Point& p ) const
{
	return grid->getAdjacentMines( p );
}
